#!/bin/sh
# PCP QA Test No. 1619
# Ensure pmcd.conf is not rewritten during every restart.
#
# Copyright (c) 2024 Red Hat.  All Rights Reserved.
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check


_cleanup()
{
    cd $here
    $sudo rm -rf $tmp $tmp.*
}

status=0	# success is the default!
trap "_cleanup; exit \$status" 0 1 2 3 15

_filter()
{
    sed \
	-e "s@$tmp@TMP@g" \
    # end
}

# real QA test starts here
inode0=`ls -i $PCP_PMCDCONF_PATH | awk '{ print $1 }'`
echo Inode0: $inode0 >> $seq_full
cp $PCP_PMCDCONF_PATH $tmp.save
cat $PCP_PMCDCONF_PATH >> $seq_full

if ! _service pmcd restart 2>&1; then _exit 1; fi | _filter_pcp_restart
_wait_for_pmcd || _exit 1
_wait_for_pmlogger || _exit 1

inode1=`ls -i $PCP_PMCDCONF_PATH | awk '{ print $1 }'`
echo Inode1: $inode1 >> $seq_full
cat $PCP_PMCDCONF_PATH >> $seq_full

echo "Comparing pmcd.conf inode numbers"
if test $inode0 -eq $inode1 
then
    echo OK
else
    echo $inode0 differs to $inode1
    status=1
fi

if diff $tmp.save $PCP_PMCDCONF_PATH
then
    :
else
    echo "Arrgh ... $PCP_PMCDONF_PATH changed"
    status=1
fi

# all done
exit
